package com.tank;

import java.awt.*;

public class Tank {
    /**
     * 横坐标
     */
    private int x;
    /**
     * 纵坐标
     */
    private int y;
    private Dir dir;
    private boolean isMoving = false;
    private final static int speed = 5;

    private TankFrame tf = null;

    public Tank(int x,int y, Dir dir, TankFrame tf) {
        this.dir = dir;
        this.x = x;
        this.y = y;
        this.tf = tf;
    }

    public Dir getDir() {
        return dir;
    }

    public void setDir(Dir dir) {
        this.dir = dir;
    }

    public boolean isMoving() {
        return isMoving;
    }

    public void setMoving(boolean moving) {
        isMoving = moving;
    }

    public void paint(Graphics graphics){
        graphics.setColor(Color.YELLOW);
        graphics.fillRect(x,y,50,50);
        move();
    }

    private void move(){
        if(!isMoving) return;

        switch (dir){
            case UP: y -= speed; break;
            case DOWN: y += speed; break;
            case LEFT: x -= speed; break;
            case RIGHT: x += speed; break;
        }

    }

    public void fire(){
        System.out.println("tank dir: " + dir);
        tf.bullets.add(new Bullet(this.x, this.y, this.dir,tf));
    }
}
